import cn.hutool.core.lang.UUID;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.bigmodel.baidu.BaiduWenXin;
import com.bigmodel.util.FtlUtil;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PromptApiV2 {

    private final static String BASE_URL = "http://localhost:8888/api";

    @Test
    public void test1() {
        String systemName= "CRM系统";
        String url = " http://localhost:8888/api/testv2/getDbStatus?name="+systemName;
        String result = HttpUtil.get(url);

        Map<String, Object> map = new HashMap<>();
        map.put("apiResponse",result);
        map.put("systemName",systemName);
        String questionContent = FtlUtil.generateContent(map, "api/getDbStatus.ftl");
        String answerContent = BaiduWenXin.chat(questionContent);
        System.out.println(answerContent);
    }


    @Test
    public void test2() {
        String systemName= "CRM系统";
        String url = " http://localhost:8888/api/testv2/restartDb?name="+systemName;
        String result = HttpUtil.get(url);

        Map<String, Object> map = new HashMap<>();
        map.put("apiResponse",result);
        map.put("systemName",systemName);
        String questionContent = FtlUtil.generateContent(map, "api/restartDb.ftl");
        String answerContent = BaiduWenXin.chat(questionContent);
        System.out.println(answerContent);
    }

    @Test
    public void test3() {
        String systemName= "CRM系统";
        String url = " http://localhost:8888/api/testv2/relationByName?name="+systemName;
        String result = HttpUtil.get(url);

        Map<String, Object> map = new HashMap<>();
        map.put("apiResponse",result);
        map.put("systemName",systemName);
        String questionContent = FtlUtil.generateContent(map, "api/relationByName.ftl");
        String answerContent = BaiduWenXin.chat(questionContent);
        System.out.println(answerContent);
    }

    @Test
    public void test4() {
        String instanceName= "adminCenter";
        String url = " http://localhost:8888/api/testv2/getInstanceStatus";

        List<String> amdbIdList = new ArrayList<>();
        amdbIdList.add(UUID.fastUUID().toString().replaceAll("-", ""));
        amdbIdList.add(UUID.fastUUID().toString().replaceAll("-", ""));

        String result =  HttpUtil.post(url, JSONUtil.toJsonStr(amdbIdList));
        Map<String, Object> map = new HashMap<>();
        map.put("apiResponse",result);
        map.put("instanceName",instanceName);
        String questionContent = FtlUtil.generateContent(map, "autotask/v2/getInstanceStatus.ftl");
        String answerContent = BaiduWenXin.chat(questionContent);
        System.out.println(answerContent);
    }

    @Test
    public void test5() {
        String instanceName= "adminCenter";
        String url = " http://localhost:8888/api/testv2/restartInstance?name="+instanceName;
        String result = HttpUtil.get(url);

        Map<String, Object> map = new HashMap<>();
        map.put("apiResponse",result);
        map.put("instanceName","adminCenter");
        String questionContent = FtlUtil.generateContent(map, "api/restartInstance.ftl");
        String answerContent = BaiduWenXin.chat(questionContent);
        System.out.println(answerContent);
    }


    @Test
    public void  relationInstanceAmdbIdBySystemName() {
        String objectName = "CRM系统";
        String url = BASE_URL+"/test/relationInstanceAmdbIdBySystemName?systemName="+objectName;
        String result = HttpUtil.get(url);

        Map<String, Object> map = new HashMap<>();
        map.put("apiResponse",result);
        map.put("systemName",objectName);
        String questionContent = FtlUtil.generateContent(map, "autotask/v2/relationInstanceAmdbIdBySystemName.ftl");
        String answerContent = BaiduWenXin.chat(questionContent);
        System.out.println(answerContent);
    }








}
